// AssessmentRepositoryV2.java
package com.university.mentalhealthplatform.teacherV2.repository;

import com.university.mentalhealthplatform.appModels.Assessment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface AssessmentRepositoryV2 extends JpaRepository<Assessment, Long> {
    @Query("SELECT a FROM Assessment a JOIN FETCH a.student WHERE a.id = :id")
    Optional<Assessment> findByIdWithStudent(@Param("id") Long id);

    @Query("SELECT a FROM Assessment a JOIN FETCH a.student")
    List<Assessment> findAllWithStudent();

    @Query("SELECT a FROM Assessment a JOIN FETCH a.student WHERE a.student.number = :sno")
    List<Assessment> findByStudent_Number(@Param("sno") String sno);

    @Query("SELECT a FROM Assessment a JOIN FETCH a.student WHERE a.evaluation LIKE %:evaluation%")
    List<Assessment> findByEvaluationContaining(@Param("evaluation") String evaluation);
}